package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Medical;
import com.tour.service.impl.MedicalServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/app/medical")
@Api(tags = "医学常识")
public class MedicalController {

    @Autowired
    MedicalServiceImpl medicalService;

    @ApiOperation("增加医学常识")
    @PostMapping("/addMedial")
    public ResponseWrapper addMedial(@RequestBody Medical medical){
        ResponseWrapper wrapper = medicalService.addMedial(medical);
        return wrapper;
    }

    @ApiOperation("删除医学常识")
    @ApiImplicitParam(name = "mid",value = "医学常识id")
    @DeleteMapping("/deleteMedical")
    public ResponseWrapper deleteMedical(@RequestParam(name = "mid")Integer mid){
        ResponseWrapper wrapper = medicalService.deleteMedical(mid);
        return wrapper;
    }
    @ApiOperation("修改医学常识")
    @PutMapping("/updateMedical")
    public ResponseWrapper updateMedical(@RequestBody Medical medical){
        ResponseWrapper wrapper = medicalService.updateMedical(medical);
        return wrapper;
    }

    @ApiOperation("查找一个医学常识")
    @ApiImplicitParam(name = "mid",value = "医学常识id")
    @GetMapping("/findOneMedical")
    public ResponseWrapper findOneMedical(@RequestParam(name = "mid")Integer mid){
        ResponseWrapper wrapper = medicalService.findOneMedical(mid);
        return wrapper;
    }

    @ApiOperation("查找所有医学常识或者模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "医学常识名称"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "当前页码",defaultValue = "1")
    })
    @GetMapping("/findMedeical")
    public ResponseWrapper findMedeical(@RequestParam(name = "name",required = false)String name,
                                        @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                        @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = medicalService.findMedeical(name,pageSize,pageNum);
        return wrapper;
    }

}

